using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_SubmitItemCell : UIBaseNode
    {
        #region Template Generate,don't modify

        protected class UIB_UIN_SubmitItemCell
        {
            #region ObjectBinding Generate

            public GameObject commonItem { protected set; get; }
            public ExText orderText { protected set; get; }
            public GameObject num { protected set; get; }
            public GameObject slot { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<GameObject>("commonItem", out var __tbv0);
                commonItem = __tbv0;
                __binding.TryGetVariableValue<ExText>("orderText", out var __tbv1);
                orderText = __tbv1;
                __binding.TryGetVariableValue<GameObject>("num", out var __tbv2);
                num = __tbv2;
                __binding.TryGetVariableValue<GameObject>("slot", out var __tbv3);
                slot = __tbv3;
            }



            #endregion ObjectBinding Generate
        }

        #endregion Template Generate,don't modify


        protected UIB_UIN_SubmitItemCell ui { get; set; }

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_SubmitItemCell();
            ui.InitBinding(csObjBind);
        }

        protected override void OnInit()
        {
            _costItem = InitChildNode<UIN_CostItem>(ui.commonItem);
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        public void RefreshCell(int index, SubmitItemData data, bool showNum)
        {
            if (data == null)
            {
                ui.slot.SetActive(true);
                _costItem.gameObject.SetActive(false);
                ui.num.gameObject.SetActive(false);
                return;
            }
            ui.slot.SetActive(false);
            _costItem.gameObject.SetActive(true);
            ui.num.gameObject.SetActive(showNum);
            ui.orderText.text = (index + 1).ToString();
            _costItem.Show(data.itemCid, data.needCnt);
        }

        protected override void OnDispose()
        {
            _costItem.Dispose();
        }

        private UIN_CostItem _costItem;
    }
}
